<include file="Public/header" />
<title>我的桌面</title>
</head>
<body>

<div class="page-container">
<h2 class="text-c" style="padding: 0;">费用分摊</h2>
    <div style="padding-top:20px;">
	
        <div id="DataTables_Table_0_wrapper" class="dataTables_wrapper no-footer">
            <table class="table table-border table-bordered table-bg table-hover table-sort dataTable no-footer" id="DataTables_Table_0" role="grid" aria-describedby="DataTables_Table_0_info">
                <thead>
                <tr class="text-c" role="row">
                    <th width="80" class="sorting_desc" tabindex="0" aria-controls="DataTables_Table_0" rowspan="1" colspan="1">ID</th>
                    <th width="200">商品名称</th>
					<th width="60">商品编码</th>
					<th width="60">价格</th>
					<th width="60">分摊金额</th>
                    <th width="60">类目</th>
                    <th width="60">仓库名称</th>
                    <th width="60">仓库编码</th>
					<th width="60">第一单位名称</th>
                    <th width="60">第一单位编码</th>
                    <th width="60">第一单位数量</th>

                </tr>
                </thead>
                <tbody>
                <foreach name="list" item="data">
                    <tr class="text-c odd" role="row">
                        <td class="sorting_1"><{$data.id}></td>
                        <td class="text-l"><{$data.name}></td>
						<td class="td-status"><{$data.goods_no}></td>
						<td><{$data.price}></td>
						<td><{$data.share_fee}></td>
                        <td><{$data.category}></td>
                        <td><{$data.warehouse_name}></td>
                        <td><{$data.warehouse_code}></td>
						 <td class="td-status">
                            <select <eq name="data.is_push" value="1">disabled="disabled"</eq> tabindex="<{$data.unit_name}>" name="unit_name">
                                <option tabindex="<{$data.u_n}>"><{$data.u_name}></option>
                                <if condition="$data.u_name_t neq null">
                                    <option tabindex="<{$data.u_n_t}>"><{$data.u_name_t}></option>
                                </if>
                            </select>
                        </td>
                        <td class="td-status"><{$data.unit_no}></td>
                        <td><span class="p_count"><{$data.count}></span></td>
                    </tr>
                </foreach>
                </tbody>
            </table>
			<div style="margin-top: 12px;">
				<a href="javascript:;" onclick="add()" class="btn btn-primary radius"><i class="Hui-iconfont"></i>添加费用名称</a>
				<table class="table table-border table-bordered table-bg">
					<thead>
						<tr>
							<th scope="col" colspan="15">费用名称列表</th>
						</tr>
						<tr class="text-c">
							<!-- <th><input type="checkbox" name=""></th> -->
							<th>序号</th>
							<th width="">费用名称编号</th>
							<th width="">费用名称名称</th>
							<th width="">金额</th>
							
						</tr>
					</thead>
					<tbody>
						<volist name="list_cost" id="vo">
						<tr class="text-c">
							<!-- <td><input type="checkbox" class="ids" name="ids" value="<{$vo.id}>" name=""></td> -->
							<td><{$i}></td>
							<td><{$vo.no}></td>
							<td><{$vo.name}></td>
							<td><input class="input-text" attr_id="<{$vo.id}>" style="width:50px" type="text" value="<{$vo.total_fee}>" name="total_fee"></td>
						</tr>
						</volist>			
					</tbody>
				</table>
				<a href="javascript:;" onclick="confirm_edit()" class="btn btn-success radius"><i class="Hui-iconfont"></i>修改</a>
				<a href="javascript:;" onclick="share_num()" class="btn btn-primary radius"><i class="Hui-iconfont"></i>按数量分摊</a>
				<a href="javascript:;" onclick="share_fee()" class="btn btn-primary radius"><i class="Hui-iconfont"></i>按金额分摊</a>
            </div>
        </div>
    </div>
    <include file="Public/footer_js" />
    <script>
		function add(){
			id=<{$Think.get.id}>;
			var index=layer.open({
				type: 2,
				title: '费用名称列表',
				shadeClose: true,
				shade: 0.5,
				area: ['1000px', '500px'],
				content: '__MODULE__/List/cost/id/'+id+'/'+Math.random() //iframe的url
			});
		}
		function confirm_edit(){
			var option = $('input[name=total_fee]');
			var ids= [];
			var prices= [];
            for(i=0;i<option.length;i++){
				ids.push(option.eq(i).attr('attr_id'));
				prices.push(option.eq(i).val());
			}
			//订单检查，是否已生成波次单
			$.ajax({
				type: 'POST',
				data: {ids:ids,prices:prices},
				url: "<{:U('cost_edit')}>",
				success:function(data){
					if(data.status==1){	//检查通过，跳转生成波次单页面
						layer.msg(data.message,function(){
							window.location.reload();
						});
						
					}else{				//检查未通过，刷新页面
						layer.msg(data.message);
					}
					return false;
				}
			})
		}
		function share_num(){
			id=<{$Think.get.id}>;
			$.ajax({
				type: 'POST',
				data: {id:id},
				url: "<{:U('share_num')}>",
				success:function(data){
					if(data.status==1){
						layer.msg(data.message,function(){
							window.location.reload();
						});
						
					}else{
						layer.msg(data.message);
					}
					return false;
				}
			})
		}
		function share_fee(){
			id=<{$Think.get.id}>;
			$.ajax({
				type: 'POST',
				data: {id:id},
				url: "<{:U('share_fee')}>",
				success:function(data){
					if(data.status==1){
						layer.msg(data.message,function(){
							window.location.reload();
						});
						
					}else{
						layer.msg(data.message);
					}
					return false;
				}
			})
		}
    </script>
</body>
</html>